    // define the module we're working with
    // define the ctrl
    app.controller("statCtrl",["$http","$scope","$location",function ($http,$scope,$location) {
         $http({method: 'GET', url: '/rooms'}).
          success(function(data, status, headers, config) {
            $scope.channels = data.rooms;
          }).
          error(function(data, status, headers, config) {
            // called asynchronously if an error occurs
            // or server returns response with an error status.
          });

        // the last received msg);
        $scope.msg = {};
        
        // handles the callback from the received event
        /*var handleCallback = function (msg) {
            $scope.$apply(function () {
                $scope.msg = JSON.parse(msg.data)
            });
        }*/
        $scope.joinChannel=function(id){

             $http({method: 'GET', url: '/room/'+id}).
             success(function(data, status, headers, config) {
              console.log("get");
                if(status == 200)
                {

                  
                  $scope.selectedChannel = id;
                  $scope.channel = data;
                  alert($scope.selectedChannel);

                  window.location.href = "room.html";
                  //$location.path("rooms");
                }
            }).
              error(function(data, status, headers, config) {
                console.log("aaa");
                // called asynchronously if an error occurs
                // or server returns response with an error status.
              });
            
        }
        $scope.createChannel = function(){
            x = $scope.form;
            $http({method: 'POST', url: '/room/create',data:x}).
             success(function(data, status, headers, config) {
            if(status == 200)
            {
              console.log(data);
              $scope.channels = data.rooms;
              //$location.path("rooms");
            }

          }).
          error(function(data, status, headers, config) {
            console.log("aaa");
            // called asynchronously if an error occurs
            // or server returns response with an error status.
          });
        }

       
  
       



        
    }]);


 /*app.controller("loginController", [ "$http", "$scope", function ( $http, $scope ){
    


}]);*/

